package com.yugong.controller;

import com.github.pagehelper.PageInfo;
import com.yugong.common.Result;
import com.yugong.entity.vo.request.CourseScoreRequestVO;
import com.yugong.entity.vo.response.CourseScoreListResponseVO;
import com.yugong.service.CourseScoreService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * 课程成绩控制器类
 *
 * @author yugong
 * @date 2024/2/25
 */
@RestController
@RequestMapping("/api/course-score")
public class CourseScoreController {
    @Resource
    private CourseScoreService courseScoreService;

    /**
     * 学生查看个人成绩
     *
     * @param studentNo 学号
     * @param pageNum   当前页
     * @param pageSize  当前页数据总数
     * @return 个人成绩
     */
    @GetMapping("/find-score-student/{studentNo}")
    public Result findScoreStudent(@PathVariable String studentNo,
                                   @RequestParam Integer pageNum,
                                   @RequestParam Integer pageSize,
                                   @RequestParam String courseName) {
        PageInfo<CourseScoreListResponseVO> courseScoreListResponseVOPageInfo
                = courseScoreService.findScoreStudent(studentNo, pageNum, pageSize, courseName);
        return Result.success(courseScoreListResponseVOPageInfo);
    }

    /**
     * 教师查看自己带的课成绩
     *
     * @param teacherNo 教师工号
     * @param pageNum   当前页
     * @param pageSize  当前页个数
     * @param courseNo  课程号
     * @return 自己带的课成绩
     */
    @GetMapping("/find-score-teacher/{teacherNo}")
    public Result findScoreTeacher(@PathVariable String teacherNo,
                                   @RequestParam Integer pageNum,
                                   @RequestParam Integer pageSize,
                                   @RequestParam String courseNo) {
        PageInfo<CourseScoreListResponseVO> courseScoreListResponseVOPageInfo
                = courseScoreService.findScoreTeacher(teacherNo, pageNum, pageSize, courseNo);
        return Result.success(courseScoreListResponseVOPageInfo);
    }

    /**
     * 企业查看自己的班的成绩
     *
     * @param businessNo  企业号
     * @param pageNum     当前页
     * @param pageSize    当前页总数
     * @param studentName 姓名
     * @return 查看自己的班的成绩
     */
    @GetMapping("/find-score-business/{businessNo}")
    public Result findScoreBusiness(@PathVariable String businessNo,
                                    @RequestParam Integer pageNum,
                                    @RequestParam Integer pageSize,
                                    @RequestParam String studentName) {
        PageInfo<CourseScoreListResponseVO> courseScoreListResponseVOPageInfo
                = courseScoreService.findScoreBusiness(businessNo, pageNum, pageSize, studentName);
        return Result.success(courseScoreListResponseVOPageInfo);
    }

    /**
     * 教师打分
     *
     * @param courseScoreRequestVO 课程成绩请求实体类
     * @return 响应码
     */
    @PutMapping("/grade-teacher")
    public Result gradeTeacher(@RequestBody CourseScoreRequestVO courseScoreRequestVO) {
        int gradeFlag = courseScoreService.gradeTeacher(courseScoreRequestVO);
        return Result.success(gradeFlag);
    }
}
